﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.LinearReferencing
{
	public class LocationIndexOfLine
	{
		public static LinearLocation[] IndicesOf(IGeometry linearGeom, IGeometry subLine)
		{
			return new LocationIndexOfLine(linearGeom).IndicesOf(subLine);
		}

		public LocationIndexOfLine(IGeometry linearGeom)
		{
			this._linearGeom = linearGeom;
		}

		public virtual LinearLocation[] IndicesOf(IGeometry subLine)
		{
			Coordinate coordinateN = ((ILineString)subLine.GetGeometryN(0)).GetCoordinateN(0);
			ILineString lineString = (ILineString)subLine.GetGeometryN(subLine.NumGeometries - 1);
			Coordinate coordinateN2 = lineString.GetCoordinateN(lineString.NumPoints - 1);
			LocationIndexOfPoint locationIndexOfPoint = new LocationIndexOfPoint(this._linearGeom);
			LinearLocation[] array = new LinearLocation[2];
			array[0] = locationIndexOfPoint.IndexOf(coordinateN);
			if (subLine.Length == 0.0)
			{
				array[1] = (LinearLocation)array[0].Clone();
			}
			else
			{
				array[1] = locationIndexOfPoint.IndexOfAfter(coordinateN2, array[0]);
			}
			return array;
		}

		private readonly IGeometry _linearGeom;
	}
}
